package top.kmtec.exception;

/**
 * @Author FengHuan Wang
 * @Date 2025/2/5 15:54
 * @Version 1.0
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.kmtec.common.BaseResponse;
import top.kmtec.common.ErrorCode;
import top.kmtec.common.ResultUtils;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessException(BusinessException e){
        log.error("系统内部错误");
        return ResultUtils.error(e.getCode(), e.getMessage(), e.getDesc());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeException(RuntimeException e){
        log.error("系统内部错误");
        return ResultUtils.error(ErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
